package com.ysj.demo.accompanynetwork.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ysj.demo.accompanynetwork.R;
import com.ysj.demo.accompanynetwork.bean.AreaBean;

import java.util.List;

/**
 * Created by 80530 on 2018/8/13.
 */

public class CityAdapter extends BaseAdapter {
    private Context mContext;
    private List<AreaBean> mList;

    public CityAdapter(Context mContext, List<AreaBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)
                mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView;
        ViewHolder holder;
        if (convertView == null) {
            rowView = inflater.inflate(R.layout.item_play_mate_layout, null);
            holder = new ViewHolder();
            holder.title = rowView.findViewById(R.id.text1);
            rowView.setTag(holder);
        } else {
            rowView = convertView;
            holder = (ViewHolder) rowView.getTag();
        }

        AreaBean sir = mList.get(position);
        if (sir != null) {
            holder.title.setText(sir.getName());
        } else {
            holder.title.setText("");
        }
        return rowView;
    }

    private class ViewHolder {
        TextView title;
    }
}
